package com.zl.dao;

import com.zl.entity.Employee;
import com.zl.utils.DataSourceUtils;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;
import org.apache.commons.dbutils.handlers.BeanListHandler;

import java.sql.SQLException;
import java.util.List;

/**
 * 数据访问类
 */
public class EmployeeDao {

    //通过工具类得到数据源给QueryRunner
    private QueryRunner runner=new QueryRunner(DataSourceUtils.getDataSource());

    /**
     * 查询所有
     */

    public List<Employee> getAll(){
        try {
           return runner.query("select * from employee",new BeanListHandler<>(Employee.class));
        } catch (SQLException e) {
            e.printStackTrace();
            throw new RuntimeException(e);
        }

    }
}
